<template>
  <!-- 历史审批意见 -->
  <div class="process-container">
    <com-table
      highlight-current-row
      :data="tableData"
      :columns="tableColumn"
      :no-page="true"
    >
      <template v-slot:checkStatus="{row}">
        {{ row.checkStatus == 0 ? '发起流程' : getDictName(checkStatus, row.checkStatus) }}
      </template>
      <template v-slot:checkTime="{row: {checkTime}}">
        {{ dateFormat(checkTime) }}
      </template>
    </com-table>
  </div>
</template>

<script>
import {
  getWorkflowSchedule
} from '@/api/flow'
import moment from 'moment'
import { getDictName } from '@/utils/comm'
import { checkStatus } from '@/utils/dicData'
export default {
  props: {
    data: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  data() {
    return {
      getDictName,
      checkStatus,
      tableData: [],
      tableColumn: [
        {
          label: '审核流程名称',
          prop: 'checkWorkflowName'
        },
        {
          label: '审核机构名称',
          prop: 'checkOrganizationName'
        },
        {
          label: '审核人',
          prop: 'checkUserName'
        },
        {
          label: '审核状态',
          prop: 'checkStatus',
          slot: 'checkStatus'
        },
        {
          label: '审核意见',
          prop: 'checkDescription'
        },
        {
          label: '审核时间',
          prop: 'checkTime',
          slot: 'checkTime'
        }
      ]
    }
  },
  watch: {
    data: {
      handler(newData, oldData) {
        if (newData.id) {
          this.initSchedule(newData.menu, newData.businessId)
        }
      },
      deep: true,
      immediate: true
    }
  },
  mounted() {
  },
  methods: {
    dateFormat(data) {
      if (data) {
        return moment(data).format('YYYY-MM-DD HH:mm:ss')
      } else {
        return ''
      }
    },
    initSchedule(menu, businessId) {
      const params = {
        menu: menu,
        businessId: businessId
      }
      getWorkflowSchedule(params).then(res => {
        const { data } = res || {}
        if (data) {
          this.tableData = data
        }
      })
    }
  }
}
</script>
